package pcvc.common.classes;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


public class Question implements Serializable
{

    /**
     * The correc value of the solution to the equation with the given values
     */
    private BigDecimal correctAnswer;

    /**
     * The equation to be solved
     */
    private Entry<String, String> equation;

    /**
     * The number of the question
     */
    private int number;

    /**
     * The question to be asked to the students
     */
    private String question;

    /**
     * The variables that the equation uses in order to be solved
     */
    private Map<String, String> variables;

    /**
     * The list of different answers given by students
     */
    private Set<StudentAnswer> studentsAnswers;

    /**
     * Creates a new method with a given question and equation.<br>
     * All lists and maps are initialized.
     * @param question The question to be asked
     * @param equation The equation of the problem
     */
    public Question( String question, Entry<String, String> equation )
    {

        correctAnswer = new BigDecimal( 0 );
        number = 0;
        studentsAnswers = new LinkedHashSet<StudentAnswer>( );
        variables = new LinkedHashMap<String, String>( );

        this.equation = equation;
        this.question = question;
    }

    /**
     * Adds a new variable to be tested in the equation
     * @param expression The expression of the variable
     * @param variable The variable itself
     */
    public void addVariable( String variable, String expression )
    {
        variables.put( variable, expression );
    }

    public BigDecimal getCorrectAnswer( )
    {
        return correctAnswer;
    }

    public void addStudentAnswer( StudentAnswer answer )
    {
        studentsAnswers.add( answer );
    }

    public void setCorrectAnswer( BigDecimal correctAnswer )
    {
        this.correctAnswer = correctAnswer;
    }

    public Entry<String, String> getEquation( )
    {
        return equation;
    }

    public void setEquation( Entry<String, String> equation )
    {
        this.equation = equation;
    }

    public int getNumber( )
    {
        return number;
    }

    public void setNumber( int number )
    {
        this.number = number;
    }

    public String getQuestion( )
    {
        return question;
    }

    public void setQuestion( String question )
    {
        this.question = question;
    }

    public Map<String, String> getVariables( )
    {
        return variables;
    }

    public void setVariables( Map<String, String> variables )
    {
        this.variables = variables;
    }

    public Set<StudentAnswer> getStudentsAnswers( )
    {
        return studentsAnswers;
    }

    public void setStudentsAnswers( Set<StudentAnswer> studentsAnswers )
    {
        this.studentsAnswers = studentsAnswers;
    }
}